package com.wyz.saas.app.mvvm

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.atom.module.mvvm.base.EmptyModel
import com.wyz.saas.app.BR
import com.wyz.saas.app.mvvm.main.TestViewModel
import com.wyz.saas.common.impl.EmptyApiModel

object AppViewModelFactory : ViewModelProvider.Factory {

    override fun <T : ViewModel?> create(modelClass: Class<T>): T {
        try {
            if (modelClass.isAssignableFrom(TestViewModel::class.java)) {
                return TestViewModel(BR.testBinding, EmptyApiModel()) as T
            }
            return modelClass.newInstance()
        } catch (e: InstantiationException) {
            throw RuntimeException("Cannot create an instance of $modelClass", e)
        } catch (e: IllegalAccessException) {
            throw RuntimeException("Cannot create an instance of $modelClass", e)
        }
    }

}